package com.cha.chaApp.sys.user.controller;

import com.cha.chaCommon.core.annotation.NoLoginCheck;
import com.cha.chaCommon.core.common.R;
import com.cha.chaApp.sys.user.param.LoginParam;
import com.cha.chaApp.sys.user.param.RegisterParam;
import com.cha.chaApp.sys.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/*
@Author  hkf
@date 2024/11/9
--轻舟已过万重山--
*/
@RestController
@Api(tags = "用户管理")
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;


    @ApiOperation(value = "登录", notes = "登录成功返回token")
    @PostMapping("/login")
    @NoLoginCheck
    public R login(LoginParam loginParam){
        String token = userService.login(loginParam);
        return R.ok(token);
    }


    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    @GetMapping("/GetCode")
    @NoLoginCheck
    public R getCode(String phone){
        String code = userService.getCode(phone);
        return R.ok(code);
    }

    @ApiOperation(value = "注册", notes = "注册")
    @PostMapping("/register")
    @NoLoginCheck
    public R getCode(RegisterParam param){
        userService.register(param);
        return R.ok();
    }
}
